#pragma data_alignment=2

#include "adr_asm.inc"

  PUBLIC  RAM_F14
  PUBLIC  RAM_SPN
  PUBLIC  RAM_IMSI
  PUBLIC  RAM_LOCI
  PUBLIC  RAM_FPLMN
  PUBLIC  LAST_SIM_BUF_POINTER
;  PUBLIC  LAST_LGP_BUF
  PUBLIC  RAM_STBY
;  PUBLIC  RAM_NET_ONLINE
;  PUBLIC  RAM_KCGPRS
;  PUBLIC  RAM_LOCIGPRS

  CODE32
  rseg Menu_Hook
  EXTERN ShowMenu
  DCB "ELSE_DEVICE_MAN"
  DCD ShowMenu

  CODE16
  rseg PATCH_BODY
  EXTERN CODE16 SIM_Cmd_Hook
  IMPORT SIM_Rsp_Hook
  IMPORT LgpHook
  IMPORT MultisimINIT
  IMPORT SaveHTTPProfile
  IMPORT SaveSMSProfile
           
;org PATCH_BASE
MsgDispatchRpl:
	push    {lr}
	push    {R0-R7}
	LDR     r4,=SIM_Rsp_Hook
	BLX     r4
	pop     {R0-R7}
	LDR     R3, =GSM_ALGHORITM_BUFFER
	LDR     R6, =off_A84F6208
	LDRH    R1, [R3,#0x2]
	SUB     R6, #0x28
	MOV     R5, #1
	LSL     R2, R1, #0x18
	pop     {PC}

Cmd_Hook1:
	mov     r6,lr
	LDR     R2, [SP,#0x1C]
	LDR     R1, [SP,#0x20]
	MOV     R0, #0
	STR     R4, [SP,#0xC]
	LDR     r4,=SIM_Cmd_Hook
	blx     r4
	mov     pc,r6

Cmd_Hook2:
	mov     r6,lr
	STR     R1, [SP,#4]
	LDR     R1, [SP,#0x20]
	LDR     R2, [SP,#0x1C]
	MOV     R0, #0
	STR     R4, [SP,#0x14]
	LDR     r4,=SIM_Cmd_Hook
	blx     r4
	mov     pc,r6
/*
StartPhoneHook:
	ADD     R6, #0x80
	MOV     R5, #0
	STR     R4, [R7,#0xC]
	STRH    R5, [R6,#0]
	MOV     R0, #0xFF
	STRB    R0, [R6,#2]
	push	{R0-R7,LR}
	LDR	r4,=MultisimINIT
	blx	r4
	pop	{R0-R7,PC}
*/

  CODE32
SetHTTPProfilel:
	MOV     R3, #0
	STRH    R0, [R1]
#ifdef SGOLD75
	STMEA   SP, {R2,R3}
#else
	STR     R3, [SP]
	STR     R3, [SP,#4]
#endif
	STMFD   SP!, {R0-R7,LR}
	LDR	r4,=SaveHTTPProfile
	blx	r4
	LDMFD   SP!, {R0-R7,PC}
                                
  CODE16

  rseg csa1
call_sim_access1:
	LDR     R2, =Cmd_Hook1
	BLX     r2
	b       csa1_e
  rseg  csa1_1:CODE(1)
csa1_e:

  rseg csa2
call_sim_access2:
	LDR     R2, =Cmd_Hook2
	BLX     r2
	b       csa2_e
  rseg  csa2_1:CODE(1)
csa2_e:

  rseg Msg_dispatch:CODE(1)
MyMsgDispatch:
  CODE16
	LDR     r4,=MsgDispatchRpl
	BLX     r4
	b       Msg_dispatch_e
  rseg Msg_dispatch_1:CODE(1)
Msg_dispatch_e:

  rseg SetHTTPProfile:CODE(2)
  CODE32
	LDR	r3,=SetHTTPProfilel
	BLX	r3
	b	SetHTTPProfile_e
                                
  rseg SetHTTPProfile_1:CODE(2)
SetHTTPProfile_e:

  CODE16
  rseg SetSMSProfile:CODE(1)
	push	{r7,lr}
	ldr	r7,=SaveSMSProfile
	blx	r7
	pop	{r7,pc}

  END
